<?php

use yii\db\Migration;

class m170922_060758_alert_classroom extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->addColumn('{{%classroom}}', 'share_count', $this->smallInteger(0) . ' default 1 comment \'同时段使用量\'');
            $this->addColumn('{{%classroom}}', 'is_share', $this->smallInteger(0) . ' default 0 comment \'是否共享 0 不共享 1 共享\'');
        }

    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropColumn('{{%classroom}}', 'share_count');
            $this->dropColumn('{{%classroom}}', 'is_share');
        }
    }
}
